package org.theSeed.singleSecurity.handlers;

import lombok.extern.slf4j.Slf4j;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.theSeed.base.pojo.sysEnum.SysCode;
import org.theSeed.base.pojo.vo.R;
import org.theSeed.web.utils.ResponseUtil;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 未授权处理
 */
@Slf4j
public class SeedAccessDeniedHandler implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        ResponseUtil.writeResponse(response, R.fail(SysCode.UN_PERMISSON,accessDeniedException.getMessage()));
    }
}
